
# if we had no trailing slash we may disable caching in the parent dir.
 
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"

# https://stackoverflow.com/a/20893337
ExpiresActive On
ExpiresDefault "now"

RewriteEngine on

# rewrite
#  https://blog.mro.name/2024/10/scaling-infrastructure/
# to
#  https://codeberg.org/mro/blog.mro.name/src/branch/ma/content/posts/2024-10-25-scaling-infrastructure

RewriteCond %{QUERY_STRING} ^redirect-rel=working-copy-of&resource=referer$
RewriteCond %{HTTP_REFERER}          ^https?://[^/]+/([0-9]+)/([0-9]+)/(.+?[^/])(/(index\.html)?)?$
RewriteRule ^(.*)$ https://codeberg.org/mro/blog.mro.name/src/branch/ma/content/posts/? [redirect=301,last]

RewriteCond %{QUERY_STRING} ^redirect-rel=working-copy-of&resource=https?://[^/]+/(.+?[^/])(/(index\.html)?)?$
RewriteRule ^(.*)$ https://codeberg.org/mro/blog.mro.name/src/branch/ma/content/posts/? [redirect=301,last]

# fallback: the webroot
RewriteCond %{QUERY_STRING} ^redirect-rel=working-copy-of&resource=referer$
RewriteRule ^(.*)$ https://codeberg.org/mro/blog.mro.name/src/branch/ma/? [redirect=301,last]
